package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.UpdateInterceptor;
import com.meida.common.mybatis.query.CriteriaUpdate;
import com.meida.module.user.client.entity.AppWorkhistory;
import com.meida.module.user.provider.service.AppWorkhistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 后台用户工作经历列表
 */
@Component
public class AppWorkhistoryCheckHandler implements UpdateInterceptor<AppWorkhistory> {

    @Autowired
    private AppWorkhistoryService appWorkhistoryService;

    @Override
    public void complete(CriteriaUpdate cu, EntityMap params, AppWorkhistory appWorkhistory) {
        Integer state = appWorkhistory.getState();
        //新经历审核通过后,把老经历删掉
        if (state == 1) {
            Long workhistoryId = appWorkhistory.getWorkhistoryId();
            AppWorkhistory oldAppWorkhistory = appWorkhistoryService.getById(workhistoryId);
            if (FlymeUtils.isNotEmpty(oldAppWorkhistory)) {
                Long parentId = oldAppWorkhistory.getParentId();
                if (FlymeUtils.isNotEmpty(parentId)) {
                    appWorkhistoryService.removeById(parentId);
                }
            }
        }
    }
}
